import { useRequest } from '@h5app/sheep/hooks'
import { EncryptSha256 } from '@h5app/sheep/utils'

export interface IResponseLogin {
  /** 用户信息 */
  userLoginData: any
  /** token */
  token: string
}

// interface ILogin {
//   /** 账号（钉钉注册手机号） */
//   account?: string
//   /** 密码登录时必传（md5加密后） */
//   password?: string
// }

// export const login = (data: ILogin): Promise<ApiRequest.ResultDto<IResponseLogin>> => {
//   const request = useRequest()
//   return request({
//     url: '/h5Web/user/login',
//     method: 'POST',
//     data,
//   })
// }
// const H5_APP_SHA256_KEY = import.meta.env.VITE_H5_APP_SHA256_KEY
// data.password = EncryptSha256(data.password || '', H5_APP_SHA256_KEY)
export const AuthRegister = (data: any): Promise<ApiRequest.ResultDto<IResponseLogin>> => {
  const request = useRequest()

  return request({
    url: '/h5Web/wechat/weChatOfficialAccountRegister',
    method: 'POST',
    data,
  })
}

export const AuthLogin = (data: any): Promise<ApiRequest.ResultDto<IResponseLogin>> => {
  const request = useRequest()

  return request({
    url: '/h5Web/wechat/weChatOfficialAccountLogin',
    method: 'POST',
    data,
  })
}

/** H5 系统登录 */
export const SystemLogin = (data: {
  account: string
  password: string
}): Promise<ApiRequest.ResultDto<IResponseLogin>> => {
  const request = useRequest()

  return request({
    url: '/crmH5/user/login',
    method: 'POST',
    data,
  })
}

export const loginFreeByDingDingCode = (code: string): Promise<API.ResultDto<IResponseLogin>> => {
  const request = useRequest()
  return request({
    url: '/crmH5/user/loginByCode',
    method: 'POST',
    data: { code },
  })
}
